set more off
clear all

local flag_hours_per_capita=1
local flag_hours_per_worker=1
local flag_wages=1
local flag_prices=1


********************************************************************************
*****************************HOURS PER CAPITA***********************************
********************************************************************************

if `flag_hours_per_capita==1' {

	import excel "Kendrick_1961\Kendrick_1961_hours.xlsx", sheet("Sheet1") clear
	rename A year
	rename B hours_Kendrick_1961
	save TEMP_kendrick_1961, replace


	import excel "Kendrick_1976\Kendrick_1976_hours.xlsx", sheet("Sheet1") clear
	rename A year
	rename B hours_Kendrick_1976
	keep year hours*
	save TEMP_kendrick_1976, replace

	use "Population\population.dta", clear
	rename population population_hist
	rename population_above_14 population_above_14_hist
	rename population_above_20 population_above_20_hist
	save TEMP_population, replace

	use "ASEC_data\ASEC_hours_population", clear

	merge 1:1 year using TEMP_kendrick_1961
	drop _merge
	merge 1:1 year using TEMP_kendrick_1976
	drop _merge
	merge 1:1 year using TEMP_population
	drop _merge


	keep if year>=1900
	gen fin_population_above_14=population_above_14_hist
	replace fin_population_above_14=fin_population_above_14[_n-1]*population_above_14/population_above_14[_n-1] if population_above_14[_n-1]!=.
	gen fin_population_above_20=population_above_20_hist
	replace fin_population_above_20=fin_population_above_20[_n-1]*population_above_20/population_above_20[_n-1] if population_above_20[_n-1]!=.

	sort year
	gen fin_hours=hours_Kendrick_1961
	replace fin_hours=fin_hours[_n-1]*hours_Kendrick_1976/hours_Kendrick_1976[_n-1] if hours_Kendrick_1976[_n-1]!=.
	replace fin_hours=fin_hours[_n-1]*hours/hours[_n-1] if hours[_n-1]!=.

	local list hours population_above_14 population_above_20
	foreach var of local list {
		rename `var'_male fin_`var'_male
		rename `var'_female fin_`var'_female
	}

	keep year fin*
	
	save data_figure_1a, replace

	gen hours_per_capita14=fin_hours/fin_population_above_14*1000
	gen hours_per_capita20=fin_hours/fin_population_above_20*1000

	gen hours_per_capita14_male=fin_hours_male/fin_population_above_14_male*1000
	gen hours_per_capita20_male=fin_hours_male/fin_population_above_20_male*1000

	gen hours_per_capita14_female=fin_hours_female/fin_population_above_14_female*1000
	gen hours_per_capita20_female=fin_hours_female/fin_population_above_20_female*1000

	keep if year<=2019
	


	line hours_per_capita20 hours_per_capita20_male hours_per_capita20_female year, lpattern(solid dash dash_dot) legend(pos(7) ring(0) col(1) label(1 "Total") label(2 "Males") label(3 "Females")) /*
		*/ylabel(500[250]2000) xlabel(1900[20]2020) xtitle("") ytitle("") /*
		*/bgcolor(white) graphregion(color(white)) plotregion(lcolor(black) lwidth(medthin)) ytitle(Annual hours) xlabel(,grid nogextend gmax) ylabel(,grid nogextend gmax)  ysize(4)
	graph export "..\figures\hours_per_capita_US_long.png", as(png) replace
	graph export "..\figures\hours_per_capita_US_long.eps", as(eps) replace
	*black and white
	line hours_per_capita20 hours_per_capita20_male hours_per_capita20_female year, lpattern(solid dash dash_dot) legend(pos(7) ring(0) col(1) label(1 "Total") label(2 "Males") label(3 "Females")) /*
		*/ylabel(500[250]2000) xlabel(1900[20]2020) xtitle("") ytitle("") /*
		*/bgcolor(white) graphregion(color(white)) plotregion(lcolor(black) lwidth(medthin)) ytitle(Annual hours) xlabel(,grid nogextend gmax) ylabel(,grid nogextend gmax)  ysize(4) scheme(s1mono)
	graph export "..\figures\hours_per_capita_US_long_bw.png", as(png) replace
	graph export "..\figures\hours_per_capita_US_long_bw.eps", as(eps) replace
	
	keep year fin_hours
	save TEMP_hours, replace

	erase TEMP_kendrick_1961.dta
	erase TEMP_kendrick_1976.dta
	erase TEMP_population.dta

}


********************************************************************************
*****************************HOURS PER WORKER***********************************
********************************************************************************

if `flag_hours_per_worker'==1 {

	import excel "Historical Statistics of the United States, Colonial Times to 1970\average_weekly_hours.xlsx", sheet("Sheet1") firstrow clear
	
	sort year
	gen hours_per_worker=D765
	replace hours_per_worker=hours_per_worker[_n-1]*D803/D803[_n-1] if (D803[_n-1]!=. & year>=1915)
	replace hours_per_worker=hours_per_worker[_n-1]*FRED/FRED[_n-1] if FRED[_n-1]!=.
	
	keep if year>=1900
	keep if year<=2019
	
	keep year hours_per_worker
	replace hours_per_worker=hours_per_worker*52
	
	save data_figure_1b, replace

	
	twoway (line hours_per_worker year), leg(off) ylabel(2000[200]3200) xlabel(1900[20]2020) xtitle("") ytitle("") /*
	*/bgcolor(white) graphregion(color(white)) plotregion(lcolor(black) lwidth(medthin)) ytitle(Annual hours) xlabel(,grid nogextend gmax) ylabel(,grid nogextend gmax)  ysize(4)
	graph export "..\figures\hours_per_worker_US_long.png", as(png) replace
	graph export "..\figures\hours_per_worker_US_long.eps", as(eps) replace
	*black and white
	twoway (line hours_per_worker year), leg(off) ylabel(2000[200]3200) xlabel(1900[20]2020) xtitle("") ytitle("") /*
	*/bgcolor(white) graphregion(color(white)) plotregion(lcolor(black) lwidth(medthin)) ytitle(Annual hours) xlabel(,grid nogextend gmax) ylabel(,grid nogextend gmax)  ysize(4) scheme(s1mono)
	graph export "..\figures\hours_per_worker_US_long_bw.png", as(png) replace
	graph export "..\figures\hours_per_worker_US_long_bw.eps", as(eps) replace
}



********************************************************************************
*********************************WAGES******************************************
********************************************************************************

if `flag_wages'==1 {

	import excel "Kendrick_1961\labor_productivity.xlsx", sheet("Sheet1") firstrow clear
	
	merge 1:1 year using TEMP_hours
	drop _merge
	
	gen wage=rGDP
	gen aux=Compensationofemployees/CPI
	
	sort year
	
	replace wage=wage[_n-1]*aux/aux[_n-1] if aux[_n-1]!=.
	
	replace wage=wage/fin_hours
	keep year wage
	keep if year>=1900
	keep if year<=2019
	
	gen byte tag=1 if year==1900
	sort tag
	gen fin_wage=wage/wage[1]
	
	save data_figure_1c, replace
	
	twoway (line fin_wage year, yaxis(1) ytitle("Wage index, 1900=1")), /*
	*/  xlabel(1900[20]2020) ylabel(1[1]10) xtitle("") /*
	*/ bgcolor(white) graphregion(color(white)) plotregion(lcolor(black) lwidth(medthin)) xlabel(,grid nogextend gmax) ylabel(,grid nogextend)  ysize(4)
	graph export "../figures/wage_US_long.png", as(png) replace
	graph export "../figures/wage_US_long.eps", as(eps) replace
	*black and white
	twoway (line fin_wage year, yaxis(1) ytitle("Wage index, 1900=1")), /*
	*/  xlabel(1900[20]2020) ylabel(1[1]10) xtitle("") /*
	*/ bgcolor(white) graphregion(color(white)) plotregion(lcolor(black) lwidth(medthin)) xlabel(,grid nogextend gmax) ylabel(,grid nogextend)  ysize(4) scheme(s1mono)
	graph export "../figures/wage_US_long_bw.png", as(png) replace
	graph export "../figures/wage_US_long_bw.eps", as(eps) replace
	
	erase TEMP_hours.dta

}


********************************************************************************
**************************RECREATION PRICES*************************************
********************************************************************************

if `flag_prices'==1 {
	import excel "Owen, the demand for leisure\Price_owen.xlsx", sheet("Sheet1") firstrow clear
	
	rename Year year
	save TEMP_owen, replace
	
	import excel "Historical Statistics of the United States, Colonial Times to 1970\recreation_price.xlsx", sheet("Sheet1") firstrow clear
	gen price_real_mid=price_rec/price_all
	keep year price_real_mid
	save TEMP_mid, replace
	
	use "BLS, price\price_rec_real_USA", clear
	keep year price_rec_real
	merge 1:1 year using TEMP_owen
	drop _merge
	merge 1:1 year using TEMP_mid
	drop _merge
	
	sort year
	
	
	gen price=real_price_owen
	replace price=price[_n-1]*price_real_mid/price_real_mid[_n-1] if price_real_mid[_n-1]!=.
	replace price=price[_n-1]*price_rec_real/price_rec_real[_n-1] if price_rec_real[_n-1]!=.

	gen byte tag=1 if year==1901
	sort tag
	gen fin_price=price/price[1]
	
	sort year
	keep if year<=2019
	
	preserve
		keep year fin_price
		save data_figure_1d, replace
	restore

	
	twoway (line fin_price year, lpattern(solid) yaxis(1) ytitle("Recreation price index, 1901=1", axis(1))), /*
	*/ xlabel(1900[20]2020) ylabel(0.4[0.1]1) xtitle("") /*
	*/ bgcolor(white) graphregion(color(white)) plotregion(lcolor(black) lwidth(medthin)) xlabel(,grid nogextend gmax) ylabel(,grid nogextend)  ysize(4)
	graph export "../figures/price_US_long.png", as(png) replace
	graph export "../figures/price_US_long.eps", as(eps) replace
	*black and white
	twoway (line fin_price year, lpattern(solid) yaxis(1) ytitle("Recreation price index, 1901=1", axis(1))), /*
	*/ xlabel(1900[20]2020) ylabel(0.4[0.1]1) xtitle("") /*
	*/ bgcolor(white) graphregion(color(white)) plotregion(lcolor(black) lwidth(medthin)) xlabel(,grid nogextend gmax) ylabel(,grid nogextend)  ysize(4) scheme(s1mono)
	graph export "../figures/price_US_long_bw.png", as(png) replace
	graph export "../figures/price_US_long_bw.eps", as(eps) replace
	
	keep if year>=1950
	keep year fin_price
	rename fin_price price_rec_real
	save US_long_price_series, replace

	erase TEMP_owen.dta
	erase TEMP_mid.dta
}

erase data_figure_1a.dta
erase data_figure_1b.dta
erase data_figure_1c.dta
erase data_figure_1d.dta

